class DataInitController < ApplicationController
    public
    def init_langzhengs
      read_file nil,"/usr/data/data/alibaba/2007EMail/"
    end
    private
    def read_file(parent,path)
       parent_id=-1
       if parent
                 parent_id=parent.id
       end
       d = Dir.new(path)
       d.each do |f|   
            filePath = path+f
            if File.file? filePath 
              item = Langzheng.new(
                                  :file_name=>File.basename(filePath),
                                  :file_size=>File.size(filePath),
                                  :extend_name=>File.extname(filePath),
                                  :user_id=>1,
                                  :is_directory=>false,
                                  :parent_id=>parent_id,
                                  :file_change_time=>File.ctime(filePath),
                                  :file_access_time=>File.ctime(filePath)
                                  ) 
                
               item.save
            end
            if File.directory? filePath
              if f=="." || f==".." 
              else 
                item = Langzheng.new(
                                  :file_name=>File.basename(filePath),
                                  :file_size=>File.size(filePath),
                                  :extend_name=>File.extname(filePath),
                                  :user_id=>1,
                                  :is_directory=>true,
                                  :parent_id=>parent_id,
                                  :file_change_time=>File.ctime(filePath),
                                  :file_access_time=>File.ctime(filePath)
                                  ) 
               item.save            
               read_file item,filePath+"/"
              end
               
            end
       end
    end
end
